# p7zip
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../func
. ../build.conf
######http://downloads.sourceforge.net/project/p7zip/p7zip/9.20.1/p7zip_9.20.1_src_all.tar.bz2
URL=http://downloads.sourceforge.net/project/p7zip/p7zip/9.20.1
PKG=p7zip
VER=9.20.1
SRCVER=${PKG}_${VER}_src_all
COMP=tar.bz2
DESC="file archiver with the highest compression ratio"
DEPS=
CAT=BuildingBlock
DESKTOP=p7zip_9.20.1_src_all.tar.bz2.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD

ARCH=$(uname -m)
case $ARCH in
 #*64) LIBDIR=lib64 ;;
 *) LIBDIR=lib ;;
esac

build() {
	mkdir -p ${PKG}-install/usr/bin
	mkdir -p ${PKG}-install/usr/share/man/man1
	mkdir -p ${PKG}-install/usr/share/doc
	mkdir -p ${PKG}-install/usr/libexec/$PRGNAM
	cd ${PKG}_${VER}
	cp makefile.linux_x86_ppc_alpha_gcc_4.X makefile.machine
	# "Stolen" from gentoo
	sed -i -e "s:OPTFLAGS=-O:OPTFLAGS=${CXXFLAGS}:" -e 's:-s ::' makefile*
	make all3
	[ "$?" -eq 0 ] || exit
	cp -ap bin/* ../${PKG}-install/usr/libexec/$PRGNAM
	cp -ap man1/* ../${PKG}-install/usr/share/man/man1
	mv contrib/gzip-like_CLI_wrapper_for_7z/p7zip contrib/gzip-like_CLI_wrapper_for_7z/7zg
	cp contrib/gzip-like_CLI_wrapper_for_7z/7zg ../${PKG}-install/usr/bin
	# Create the wrapper scripts
	cat > ../${PKG}-install/usr/bin/7za <<EOF
#!/bin/sh
exec /usr/libexec/7za "\$@"
EOF

	cat > ../${PKG}-install/usr/bin/7z <<EOF
#!/bin/sh
exec /usr/libexec/7z "\$@"
EOF
	chmod 755 ../${PKG}-install/usr/bin/*
	chmod 755 ../${PKG}-install/usr/libexec/*
	cd -
}
	
package() {
	# add this recipe
	mv ${PKG}-install ${PKG}-${VER}-${ARCH}_${BUILD}
	install -d -m 0755 ${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/src/dev
	cat ${PKG}.petbuild > ${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/src/dev/${PKG}-build-recipe
	for p in $(ls|grep "\-${ARCH}"|grep -v "files$") ; do
		case $p in
			*_DEV*) DESC="$PKG development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="$PKG documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="$PKG locales"; DEPS=+${PKG} ;;
		esac	
		echo "packaging $p"	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c="$CAT" -p=${p} 2>&1 >/dev/null
		rm -r $p
		mv ${p}.pet ../0pets_out
	done
	#rm -r ${PKG}-install
	rm -r ${PKG}_${VER}
	#mv -f *.files ../0logs
	echo "done!"
}

# main
retrieve ${SRCVER}.${COMP}
extract ${SRCVER}.${COMP}
build
package	
